package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.MouseJoint;
import com.badlogic.gdx.physics.box2d.joints.MouseJointDef;

public class MouseJointFactory extends JointFactory<MouseJointFactory>
{
	private static final MouseJointDef _initialDef = new MouseJointDef();
	
	private MouseJointDef _def;
	
	public MouseJointFactory()
	{
		this(false);
	}
	
	MouseJointFactory(boolean managed)
	{
		super(managed);
		_def = new MouseJointDef();
		setDef(_def);
	}
	
	public MouseJointFactory dampingRatio(float r)
	{
		_def.dampingRatio = r;
		return this;
	}
	
	public MouseJointFactory frequencyHz(float f)
	{
		_def.frequencyHz = f;
		return this;
	}
	
	public MouseJointFactory maxForce(float f)
	{
		_def.maxForce = f;
		return this;
	}
	
	public MouseJointFactory target(Vector2 t)
	{
		_def.target.set(t);
		return this;
	}
	
	public MouseJointFactory target(float x, float y)
	{
		_def.target.set(x, y);
		return this;
	}
	
	public MouseJoint create(World w)
	{
		return (MouseJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.dampingRatio = _initialDef.dampingRatio;
		_def.frequencyHz = _initialDef.frequencyHz;
		_def.maxForce = _initialDef.maxForce;
		_def.target.set(_initialDef.target);
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
